home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.2 / Audio / release.3.early / rel3.demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.5 KB  |  126 lines

  1. /* auToolDemo1.c */
  2.  
  3. /* #define DEBUG 1 */
  4.  
  5. #include "exec/types.h"
  6. #include "exec/memory.h"
  7. #include "devices/audio.h"
  8. #include "ram:audiotools3.c"
  9.  
  10. BYTE *noise;
  11.  
  12. main()
  13. {
  14.    LONG i, channel, error, note;
  15.  
  16.    struct MsgPort *myport;   /* CHANGE from article */
  17.  
  18.    noise = (BYTE *)AllocMem(1024, MEMF_CHIP);
  19.  
  20.    for(i=0; i<1024; i++)
  21.    {
  22.     /* Use a PseudoRandom number generator to get white noise */
  23.  
  24.     noise[i] = 127 - RangeRand(256);
  25.    } 
  26.  
  27.  
  28.    myport = InitAudio();   /* now returns address of message port */
  29.    if(myport == 0) 
  30.    {
  31.     printf("Problem in InitAudio!");
  32.     FinishAudio(myport);
  33.    }
  34.    for(i=0; i<4; i++) 
  35.    {   
  36.       channel = GetChannel(-1);
  37.       if(channel == -1)
  38.       {
  39.        printf("cannot get a channel!\n");
  40.        FinishAudio(myport);
  41.       }
  42.  
  43.       error = StopChannel(channel);
  44.       if(error) 
  45.       {  
  46.      printf("error in stopping channel = %ld\n",error);
  47.          FinishAudio(myport);
  48.       }
  49.    }
  50.    /*  (channel, note, waveform, vol, duration, priority,messageport, id) */
  51.  
  52.    for(i=0; i<49; i++)
  53.    {
  54.       /* frequency of "zero" is not useful */
  55.  
  56.       PlayFreq(0, (i+1)*10, w1, 32, 125, 0, 0, 0); /* all notes, 1/8 sec. */
  57.       PlayNote(1, 95-i,     w2, 32, 125, 0, 0, 0); 
  58.    }
  59.  
  60.    /* SMACK IN THE MIDDLE HERE, INSTALL TEST OF MESSAGING */
  61.    /* cause it to flash the screen when this note begins to play */
  62.    /* Make the note distinctive so we can tell for sure */
  63.  
  64.    PlayNote(1, 3,           w3, 63, 500, 0, myport, 3);  /* very LOUD and low */
  65.    
  66.    for(i=50; i<95; i++)
  67.    {
  68.       PlayFreq(0, (i+1)*10, w1, 32, 125, 0, 0, 0); /* all notes, 1/8 sec. */
  69.       PlayNote(1, 95-i,     w2, 32, 125, 0, 0, 0); 
  70.    }
  71.  
  72.    for(i=0; i<4; i++)
  73.    {   
  74.     error = StartChannel(i);
  75.         if(error)  
  76.     {
  77.         printf("error starting channel = %ld\n",error);
  78.         FinishAudio(myport);
  79.     }
  80.    }
  81.  
  82.    /* Now SLEEP while waiting for that note to play */
  83.  
  84.    printf("Going to sleep now - the prioritized note will wake me up\n");
  85.  
  86.    note = MayGetNote(myport, TRUE);    /* FALSE means don't sleep */
  87.  
  88.    printf("\n\n\n****************************************************\n");
  89.    printf("Hey!  Note I identified as: %ld just started to play\n",note);
  90.    printf("\n****************************************************\n\n\n");
  91.  
  92.    /* When we hit the PlayNote, it calls GetIOB, which in turn
  93.     * begins to remove iob's from the reply port, freeing them
  94.     * for future use.  You might consider changing the ReEmployIOB
  95.     * routine to simply free 1 or 10 or whatever number, just so 
  96.     * you could begin to play another note before ALL of the already
  97.     * played note's iob's had been freed.  But when DEBUG is turned
  98.     * off, the freeing goes a lot faster.
  99.     */
  100.  
  101.    Delay(250);    /* waits 5 seconds so that all of these synchronize */
  102.  
  103.    PlayNote(0, 23, w1, 32, 2000, 0, 0, 0);
  104.    PlayNote(1, 27, w2, 32, 2300, 0, 0, 0);
  105.    PlayNote(2, 30, w3, 32, 2600, 0, 0, 0);
  106.    PlayNote(3, 35, w1, 32, 2900, 0, 0, 0);
  107.  
  108.    printf("Finally, some noise, using PlaySamp\n");
  109.    PlaySamp(0,    327,    &noise[0],  32,     6000,  0,    0,    0,   1024 );
  110.    /*    chan, samplrate, what2play, volume, 6.0sec, pri, msgpt, id, length */
  111.  
  112.    Delay(450);    /* Waits 9 seconds after letting the last note begin
  113.          * (because last note is 2900/1000ths long).
  114.          * If you take out this delay, you'll see that
  115.          * FinishAudio means FINISH AUDIO... it cuts off
  116.          * the notes right in the middle if necessary!
  117.          */
  118.  
  119.  
  120.    FinishAudio(myport);   /* NEW parameter for FinishAudio */
  121.    FreeMem(noise, 1024);
  122.  
  123.    printf("Done!\n");
  124.    return(0);
  125. }         /* end of main() */
  126.